﻿namespace WMS6.Services
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using WMS6.BLL;
    using WMS6.Common;
    using WMS6.DataEntity;

    [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed), ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
    public class OrderDetailMgtService : IOrderDetailMgtService
    {
        public string DeletePurchaseOrderDetail(List<string> poIDs, List<string> lineIDs, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new PurchaseOrderDetailBLL(pubParasInfo).DeleteDetail(poIDs, lineIDs);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Delete_PurchaseOrderDetail", poIDs, lineIDs, pubParasInfo);
                return temp;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return temp;
        }

        public string DeleteSalesOrderDetail(string salesOrderID, List<string> lineIDs, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderDetailBLL(pubParasInfo).DeleteSalesOrderDetail(salesOrderID, lineIDs);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Delete_SalesOrderDetail", salesOrderID, lineIDs, pubParasInfo);
                return temp;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return temp;
        }

        public DataSet GetAllpurchaseOrderDetailInfo(PubParasInfo pubParasInfo)
        {
            try
            {
                PurchaseOrderDetailBLL purchaseOrderDetailBll = new PurchaseOrderDetailBLL(pubParasInfo);
                return purchaseOrderDetailBll.GetAllpurchaseOrderDetailInfo();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return null;
        }

        public PurchaseOrderDetailInfo GetPurchaseOrderDetailInfoByID(string poID, string lineID, PubParasInfo pubParasInfo)
        {
            PurchaseOrderDetailInfo purchaseOrderDetailInfo = new PurchaseOrderDetailInfo();
            try
            {
                PurchaseOrderDetailBLL purchaseOrderDetailBll = new PurchaseOrderDetailBLL(pubParasInfo);
                return purchaseOrderDetailBll.GetDetailInfoByID(poID, lineID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return purchaseOrderDetailInfo;
        }

        public List<PurchaseOrderDetailInfo> GetPurchaseOrderDetailInfoListByID(string poID, PubParasInfo pubParasInfo)
        {
            List<PurchaseOrderDetailInfo> purchaseOrderDetailInfos = new List<PurchaseOrderDetailInfo>();
            try
            {
                PurchaseOrderDetailBLL purchaseOrderDetailBll = new PurchaseOrderDetailBLL(pubParasInfo);
                return purchaseOrderDetailBll.GetDetailInfoListByID(poID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return purchaseOrderDetailInfos;
        }

        public SalesOrderDetailInfo GetSalesOrderDetailInfoByID(string poID, string lineID, PubParasInfo pubParasInfo)
        {
            SalesOrderDetailInfo salesOrderDetailInfo = new SalesOrderDetailInfo();
            try
            {
                SalesOrderDetailBLL salesOrderDetailBLL = new SalesOrderDetailBLL(pubParasInfo);
                return salesOrderDetailBLL.GetSalesOrderDetailByID(poID, lineID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return salesOrderDetailInfo;
        }

        public string InsertPurchaseOrderDetail(PurchaseOrderDetailInfo purchaseOrderDetailInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderDetailBLL(pubParasInfo).InsertDetail(purchaseOrderDetailInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Insert_PurchaseOrderDetail", purchaseOrderDetailInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return lineID;
        }

        public string InsertSalesOrderDetail(SalesOrderDetailInfo salesOrderDetailInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderDetailBLL(pubParasInfo).InsertSalesOrderDetail(salesOrderDetailInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Insert_SalesOrderDetail", salesOrderDetailInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return lineID;
        }

        public string PurchaseOrderDetailPriceChanges(string PoID, string poLineID, float price, float totalprice, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                PurchaseOrderDetailBLL purchaseOrderDetailBLL = new PurchaseOrderDetailBLL(pubParasInfo);
                return purchaseOrderDetailBLL.purchaseOrderDetailPriceChanges(PoID, poLineID, price, totalprice);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return temp;
        }

        public string UpdatePurchaseOrderDetail(PurchaseOrderDetailInfo purchaseOrderDetailInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderDetailBLL(pubParasInfo).UpdateDetail(purchaseOrderDetailInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Update_PurchaseOrderDetail", purchaseOrderDetailInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return lineID;
        }

        public string UpdateSalesOrderDetail(SalesOrderDetailInfo salesOrderDetailInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderDetailBLL(pubParasInfo).UpdateSalesOrderDetail(salesOrderDetailInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderDetailMgtService_Update_SalesOrderDetail", salesOrderDetailInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderDetailMgtService异常");
            }
            return lineID;
        }
    }
}

